package com.baipeng.bp_alicloud_push.activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

import com.alibaba.sdk.android.push.AndroidPopupActivity;
import com.baipeng.bp_alicloud_push.application.PushApplication;

import java.util.HashMap;
import java.util.Map;

/**
 * 辅助推送通道指定打开的弹窗activity,目前包括:小米弹窗、华为弹窗
 */
public class ThirdPushPopupActivity extends AndroidPopupActivity {
    private static final String TAG = "MPS:ThirdPushPopupActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String packageName = getPackageName();
        Log.i(TAG, "onCreate: packageName=" + packageName);
        PackageManager packageManager = getPackageManager();
        Intent it = packageManager.getLaunchIntentForPackage(packageName);
        startActivity(it);
        this.finish();
    }

    /**
     * 弹窗消息打开互调。辅助弹窗通知被点击时,此回调会被调用,用户可以从该回调中获取相关参数进行下一步处理
     */
    @Override
    protected void onSysNoticeOpened(String title, String content, Map<String, String> extraMap) {
        Log.i(TAG, "Receive ThirdPush notification, title: " + title + ", content: " + content + ", extraMap: " + extraMap);
        Map<String, Object> map = new HashMap<>();
        map.put("title", title);
        map.put("body", content);
        map.put("extra", extraMap);
        PushApplication.onNotification(map);
    }
}
